<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Preference</title>
<link rel="stylesheet" type="text/css" href="jquery/jquery.mobile-1.0a4.1.css" />
<script src="jquery/jquery-1.6.1.min.js"></script>
<script src="jquery/jquery.mobile-1.0a4.1.js"></script>
<script type="text/javascript">
	$('document').ready(function() {
		$.getJSON('get_preset.php', {user_id: sessionStorage['user_id']}, function(data) {
			$('#bus_numbers').val(data.bus_numbers == 'null' ? "" : data.bus_numbers);
			$('#facebook_id').val(data.facebook_id == 'null' ? "" : data.facebook_id);
			$('#crime_rate').val(parseFloat(data.crime_rate) * 100);	
		});
	});
	
	function save() {
		$.post('post_preset.php', {user_id: sessionStorage['user_id'], 
									bus_numbers: $('#bus_numbers').val(), 
									facebook_id: $('#facebook_id').val(),
									crime_rate: parseFloat($('#crime_rate').val())/100}, function(data) {
			if (data.status != 0)
				alert('에러 발생');
			else
				alert('저장되었습니다');
		}, "json");
	}
</script>
</head>
<body>
<div data-role="page" data-theme="b">
	<div data-role="header">
		<h1>Setup Preference</h1>
	</div>
	<div data-role="content" data-theme="c">
		<form action="" method="get">
			<div data-role="fieldcontain">
				<label for="bus_numbers">주 이용버스 번호(, 로 구분)</label>
				<input type="text" name="bus_numbers" id="bus_numbers" value=""  />
				<label for="facebook_id">FaceBook ID</label>
				<input type="text" name="facebook_id" id="facebook_id" value=""  />
				<label for="crime_rate">허용 범죄율(%)</label>
				<input type="text" name="crime_rate" id="crime_rate" value=""  />
			</div>
			<input type="button" value="Save" onclick="save()" />
		</form>
	</div>
	<div data-role="footer" data-theme="a">
		<div data-role="navbar">
			<ul>
				<li><a href="service_list.html" data-icon="grid">Services</a></li>
				<li><a rel="external" href="context_monitor.html" class="ui-btn-active" data-icon="star">Monitor</a></li>
			</ul>
		</div>
	</div>
</div>
</body>
</html>